﻿#region Header
//************************************************************************************
// Name: FacadeExposer
// Description: class used to exposes facade methods
// Created On:  27-Dec-2011
// Created By:  Swathi
// Last Modified On:
// Last Modified By: 
// Last Modified Reason: 
//*************************************************************************************
#endregion Header
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using Chinook.Facade;
using Chinook.Core.DaoInterface;
using Base.Common;
using Base.Utils;
namespace Chinook.Facade.Ioc
{
   public class FacadeExposer
    {
       private IProfilerService _profilerService;
          public IProfilerService ProfilerService
       {
           get
           {
               if (_profilerService != null)
                   return _profilerService;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _profilerService = (IProfilerService)ctx.GetObject("ProfilerService");

               if (_profilerService == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _profilerService;
           }
       }

       private IEmployeeAppService _employeeAppService;
       public IEmployeeAppService EmployeeAppService
       {
           get
           {
               if (_employeeAppService != null)
                   return _employeeAppService;
               IApplicationContext ctx = ContextRegistry.GetContext();
               Base.Utils.Factory.UtilsFactory.Logger.Log(ctx.ToString(), Base.Utils.Logging.LogType.Info);
               _employeeAppService = (IEmployeeAppService)ctx.GetObject("EmployeeAppService");

               if (_employeeAppService == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _employeeAppService;
           }
       }

       private IAlbumAppService _albumAppService;
       public IAlbumAppService AlbumAppService
       {
           get
           {
               if (_albumAppService != null)
                   return _albumAppService;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _albumAppService = (IAlbumAppService)ctx.GetObject("AlbumAppService");

               if (_albumAppService == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _albumAppService;
           }
       }

       private IEmployeeDao _employeeDao;
       public IEmployeeDao EmployeeDao
       {
           get
           {
               if (_employeeDao != null)
                   return _employeeDao;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _employeeDao = (IEmployeeDao)ctx.GetObject("EmployeeDao");

               if (_employeeDao == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _employeeDao;
           }
       }

       private IInvoiceAppService _invoiceAppService;
       public IInvoiceAppService InvoiceAppService
       {
           get
           {
               if (_invoiceAppService != null)
                   return _invoiceAppService;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _invoiceAppService = (IInvoiceAppService)ctx.GetObject("InvoiceAppService");

               if (_invoiceAppService == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _invoiceAppService;
           }
       }
       private IInvoiceDao _invoiceDao;
       public IInvoiceDao InvoiceDao
       {
           get
           {
               if (_invoiceDao != null)
                   return _invoiceDao;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _invoiceDao = (IInvoiceDao)ctx.GetObject("InvoiceDao");

               if (_invoiceDao == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _invoiceDao;
           }
       }

       private IAlbumDao _albumDao;
       public IAlbumDao AlbumDao
       {
           get
           {
               if (_albumDao != null)
                   return _albumDao;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _albumDao = (IAlbumDao)ctx.GetObject("AlbumDao");

               if (_albumDao == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _albumDao;
           }
       }

       private ICustomerDao _customerDao;
       public ICustomerDao CustomerDao
       {
           get
           {
               if (_customerDao != null)
                   return _customerDao;
               IApplicationContext ctx = ContextRegistry.GetContext();
               _customerDao = (ICustomerDao)ctx.GetObject("CustomerDao");

               if (_customerDao == null)
                   throw new TypeLoadException("Can not load object from container!");
               return _customerDao;
           }
       }

       //property to hold instance for IDMSAppService
       private IDMSAppService  _dmsAppService;
       /// <summary>
       /// Method used to get DMSAppService object from Context Registry
       /// </summary>
       public IDMSAppService DMSAppService
       {
           //getter method
           get
           {
               //check whether _dmsAppService is not null
               if (_dmsAppService != null)
                   //return facade object if not null
                   return _dmsAppService;
               //instance to Get Context of Context Registry
               var ctx = ContextRegistry.GetContext();
               //Get dms service object from Context
               _dmsAppService = (IDMSAppService)ctx.GetObject("DMSAppService");
               //check _dmsAppService is null
               if (_dmsAppService == null)
                   //if _dmsAppService is null throw type load exception
                   throw new TypeLoadException("Can not load facade service Factory from container!");
               //return dms service object
               return _dmsAppService;
           }
       }

       //property to hold instance for IDmsDao
       private IDmsDao _dmsDao;
       /// <summary>
       /// Method used to get DMSDao object from Context Registry
       /// </summary>
       public IDmsDao DMSDao
       {
           //getter method
           get
           {
               //check whether _dmsDao is not null
               if (_dmsDao != null)
                   //return Dao object if not null
                   return _dmsDao;
               //instance to Get Context of Context Registry
               var ctx = ContextRegistry.GetContext();
               //Get dao object from Context
               _dmsDao = (IDmsDao)ctx.GetObject(AppSettings.Instance.dms_environment.ToLower().Trim());
               //check _dmsDao is null
               if (_dmsDao == null)
                   //if _dmsDao is null throw type load exception
                   throw new TypeLoadException("Can not load dao from container!");
               //return dao object
               return _dmsDao;
           }
       }
    }
}
